package com.zpark.it.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zpark.it.mapper.GradeMapper;
import com.zpark.it.pojo.Grade;
import com.zpark.it.service.GradeService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * @Title: GradeServiceImpl
 * @Author Charles
 * @Package com.zpark.it.service.impl
 * @Date 2023/7/29 21:14
 */
@Service
@Transactional
public class GradeServiceImpl extends ServiceImpl<GradeMapper, Grade> implements GradeService {
    /**
     * 分页查询
     * @param pageParam
     * @param gradeName
     * @return
     */
    @Override
    public IPage<Grade> getGradeByOpr(Page<Grade> pageParam, String gradeName) {
        QueryWrapper<Grade> queryWrapper=new QueryWrapper<>();
        if (!StringUtils.isEmpty(gradeName)) {
            queryWrapper.like("name",gradeName);

        }
        queryWrapper.orderByDesc("id");//根据id降序查询
        Page<Grade> page = baseMapper.selectPage(pageParam, queryWrapper);

        return page;
    }

    /**
     * 获取全部年级
     * @return
     */
    @Override
    public List<Grade> getGrades() {

        return baseMapper.selectList(null);

    }
}
